﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using Maticsoft.BLL;
using Maticsoft.Model;

namespace FineUI.Examples
{
    public partial class admin_manage_student : System.Web.UI.Page
    {
        protected DataSet LoadStudentInformation()
        {
            Maticsoft.BLL.Student ST = new Maticsoft.BLL.Student();
            DataSet DSStudent = ST.GetAllList();

            DataView DVStudent=DSStudent.Tables[0].DefaultView;
            GridStudent.DataSource = DVStudent;
            GridStudent.DataBind();
            return DSStudent;   
        
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }
            LoadStudentInformation();
        }

        protected void GridStudent_RowClick(object sender, GridRowClickEventArgs e)
        {
            int index = e.RowIndex;
            DataSet currentDataSet = LoadStudentInformation();

            string currentS_Id = currentDataSet.Tables[0].Rows[index]["S_Id"].ToString();
            string current_S_Password = currentDataSet.Tables[0].Rows[index]["S_Password"].ToString();
            string current_S_Name = currentDataSet.Tables[0].Rows[index]["S_Name"].ToString();
            string current_S_Sex = currentDataSet.Tables[0].Rows[index]["S_Sex"].ToString();
            string current_S_Contact = currentDataSet.Tables[0].Rows[index]["S_Contact"].ToString();
            string current_S_Email = currentDataSet.Tables[0].Rows[index]["S_Email"].ToString();
            string current_S_Department = currentDataSet.Tables[0].Rows[index]["S_Department"].ToString();

            tbxUserName.Text = currentS_Id;
            tbxPassword.Text = current_S_Password;
            tbxName.Text = current_S_Name;
            tbxSex.Text = current_S_Sex;
            tbxConnect.Text = current_S_Contact;
            tbxEmail.Text = current_S_Email;
            tbxDepartment.Text = current_S_Department;

        }

        protected void GridStudent_PageIndexChange(object sender, GridPageEventArgs e)
        {
            GridStudent.PageIndex = e.NewPageIndex;
            LoadStudentInformation();
        }

        protected void btnUpdateStuInform_Click(object sender, EventArgs e)
        {
            if (tbxUserName.Text == "")
            {
                Alert.Show("请选中一行", MessageBoxIcon.Information);
                return;
            }
            string currentS_Id = tbxUserName.Text;
            string current_S_Password = tbxPassword.Text;
            string current_S_Name = tbxName.Text;
            string current_S_Sex = tbxSex.Text;
            string current_S_Contact = tbxConnect.Text;
            string current_S_Email = tbxEmail.Text;
            string current_S_Department = tbxDepartment.Text;

            Maticsoft.BLL.Student ST = new Maticsoft.BLL.Student();
            Maticsoft.Model.Student STInfrom = ST.GetModel(currentS_Id);

            STInfrom.S_Password = current_S_Password;
            STInfrom.S_Name = current_S_Name;
            STInfrom.S_Sex = current_S_Sex;
            STInfrom.S_Contact = current_S_Contact;
            STInfrom.S_Email = current_S_Email;
            STInfrom.S_Department = current_S_Department;

            if (!ST.Update(STInfrom))
            {

                Alert.ShowInTop("修改信息失败！", MessageBoxIcon.Information);

            }
            LoadStudentInformation();

        }

    }
}